package main

//
//import (
//	"fmt"
//	"gin-ranking/common/zinx/ziface"
//	"gin-ranking/common/zinx/znet"
//)
//
//// PingRouter ping test 自定义路由
//type PingRouter struct {
//	znet.BaseRouter
//}
//
//// Handle Test
//func (p *PingRouter) Handle(request ziface.IRequest) {
//	fmt.Println("Call Router Handle...")
//	// 读取客户端数据，写回 ping..ping
//	fmt.Println("recv from client: msgId = ", request.GetMsgId(), ", data = ", string(request.GetData()))
//	if err := request.GetConnection().SendMsg(1, []byte("ping..ping..ping..ping..ping..ping..ping..ping..ping..ping..")); err != nil {
//		fmt.Println("err =", err)
//	}
//}
//
//// HelloRouter hello Zinx test 自定义路由
//type HelloRouter struct {
//	znet.BaseRouter
//}
//
//// Handle Test
//func (h *HelloRouter) Handle(request ziface.IRequest) {
//	fmt.Println("Call HelloZinxRouter Handle...")
//	// 先读取客户端的数据，再回写 ping..ping..ping
//	fmt.Println("recv from client: msgID = ", request.GetMsgId(), ", data = ", string(request.GetData()))
//	if err := request.GetConnection().SendMsg(1, []byte("Hello! Welcome to Zinx!")); err != nil {
//		fmt.Println(err)
//	}
//}
//
//// DoConnectionBegin 创建连接之后执行的钩子函数
//func DoConnectionBegin(conn ziface.IConnection) {
//	fmt.Println("====> DoConnectionBegin is Called...")
//	if err := conn.SendMsg(202, []byte("DoConnection BEGIN!")); err != nil {
//		fmt.Println(err)
//	}
//	// 给当前连接设置一些属性
//	fmt.Println("Set conn property...")
//	conn.SetProperty("Name", "刘舟冰")
//	conn.SetProperty("GitHub", "https://github.com/aceld")
//}
//
//// DoConnectionLost 连接断开前执行的钩子函数
//func DoConnectionLost(conn ziface.IConnection) {
//	fmt.Println("====> DoConnectionLost is Called...")
//	fmt.Println("conn ID = ", conn.GetConnID(), " is Lost...")
//
//	// 获取连接属性
//	if name, err := conn.GetProperty("Name"); err == nil {
//		fmt.Println("Name = ", name)
//	}
//	if github, err := conn.GetProperty("GitHub"); err == nil {
//		fmt.Println("GitHub = ", github)
//	}
//}
//
//func main() {
//	// 1 创建一个server句柄, 使用Zinx的api
//	server := znet.NewServer("[Zinx V0.6]")
//
//	// 注册 hook 函数
//	server.SetOnConnStart(DoConnectionBegin)
//	server.SetOnConnStop(DoConnectionLost)
//
//	// 2 给当前 zinx 框架添加一个自定义的router
//	server.AddRouter(0, &PingRouter{})
//	server.AddRouter(1, &HelloRouter{})
//	// 3 启动server
//	server.Server()
//}
